<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>区分不同类的同名私有字段</title>
</head>

<body>
    in 运算符可以正确区分不同类的同名私有字段：
    <hr />
    作者：广州蓝景实训部
    链接：https://www.zhihu.com/question/24692840/answer/2621670010
    来源：知乎
    著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。
    <script>
        class Car {
            #color;
            hasColor() {
                return #color in this;
            }
        }
        class House {
            #color;
            hasColor() {
                return #color in this;
            }
        }
        const car = new Car();
        const house = new House();
        console.log(car.hasColor()); // true;
        console.log(car.hasColor.call(house)); // false
        console.log(house.hasColor()); // true
        console.log(house.hasColor.call(car)); // false


    </script>
</body>

</html>